package com.khoinguyen.feedtweet.test;

import java.util.List;

import twitter4j.Status;

import com.khoinguyen.feedtweet.business.TwitterBusiness;
import com.khoinguyen.feedtweet.dao.TweetDao;
import com.khoinguyen.feedtweet.dao.UserDao;
import com.khoinguyen.feedtweet.model.VOTweet;
import com.khoinguyen.feedtweet.model.VOUser;

public class FetchAllTweets {
	public static void main(String[] args) {
		List<VOUser> users = UserDao.getAllUsers();
		System.out.println(users.size());
		for (VOUser u : users) {
			System.out.println("Processing for " + u.getUsername());
			long uid = u.getId();
			List<VOTweet> existingTweets = TweetDao.getTweetsByAuthorId(uid);
			if (existingTweets.size() == 0) {
				List<Status> statuses = TwitterBusiness.getStatusByUserId(uid);
				for (Status s : statuses) {
					VOTweet tweet = new VOTweet(s.getId(), uid, s.getText());
					TweetDao.insertTweet(tweet);
				}
			}
		}
	}
}
